package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.service.WebReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * bean模式
 */
//@JobHandler(value="webReportJobHandler")
//@Component
public class WebReportJobHandler extends IJobHandler {

    //@Resource
    private WebReportService webReportService;

    /**
     * execute handler, invoked when executor receives a scheduling request
     *
     * @param param
     * @return
     * @throws Exception
     */
    @Override
    public ReturnT<String> execute(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello WebReportJobHandler.");
        System.out.println("XXL-JOB webReportJobHandler 开始统计！");
        ReturnT<String> returnT = webReportService.collection();
        System.out.println("XXL-JOB webReportJobHandler :" + returnT.getCode());
        if(returnT.getCode() == ReturnT.FAIL_CODE) {
            return FAIL;
        }
        return SUCCESS;
    }
}
